#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/stat.h>

#define MK_PATH "/home/xiaotao/learn/month_7/day24/myfifo"

int main(int argc,const char* argv[])
{
  int ret;
  if(access(MK_PATH,F_OK) != 0)
  {
    ret = mkfifo(MK_PATH,0777);
    if(ret ==  0)
    {
       perror("mkfifo fail");
       exit(-1);
    }
  }

  int mk_fd = open(MK_PATH,O_RDWR);
  if(mk_fd < 0)
  {
    perror("open fail");
    exit(-1);
  }
  char buf[1024];
  while(1)
  {
    bzero(buf,1024);
    printf("please input data:");
    scanf("%s",buf);
    write(mk_fd,buf,strlen(buf));
    if(!strcmp(buf,"bye"))
      break;
  }

  close(mk_fd);
  return 0;
}
